import UcRequest, { UcResponse } from './ucRequest'

/**
 * 检查邮箱地址
 * 
 * 注册账户前需要先检查邮箱地址是否存在
 */
export default class UserCheckEmailRequest extends UcRequest
{
    module = 'user'
    action = 'check_email'
    httpMethod = 'get'
    constructor(email){
        super()
        this.params = {
            email: email
        }
    }
}

export class UserCheckEmailResponse extends UcResponse
{
    constructor(rawData){
        super(rawData)
        let result = parseInt(rawData)
        if(isNaN(result)){
            result = 0
        }
        this.errCode = result
        if(result > 0){
            this.isSuccess = true
            this.errMsg = '邮箱有效';
        }else{
            this.isSuccess = false;
            switch(result){
                case -4:
                    this.errMsg = 'Email 格式有误';
                    break;
                case -5:
                    this.errMsg = 'Email 不允许注册';
                    break;
                case -6:
                    this.errMsg = '该 Email 已经被注册';
                    break;
                default:
                    if(respRaw.length > 0){
                        this.errMsg = respRaw; // 如果响应的正文是文本信息，则直接作为错误消息
                    }else{
                        this.errMsg = '未知的错误！';
                    }
            }
        }
    }
}